package org.nowcoder.huawei.c200;

import java.util.Arrays;

/**
 * 2: MELON的难题
 */


public class HC002 {
    static int minCount = 10; // 用于存储最小取出的雨花石数量
    private static int total;
    private static int count;

    public static void main(String[] args) {
        boolean[] used = new boolean[10];
        int[] stones = new int[]{1, 1, 1, 1, 1, 9, 8, 3, 7, 10};
        Arrays.sort(stones);
        solve(stones, used, 21);
        System.out.println(minCount);
    }

    public static void solve(int[] stones, boolean[] used, int avg) {
        if (total >= avg) {
            if (total == avg) {
                minCount = Math.min(count, minCount);
            }
            return;
        }

        for (int i = 0; i < stones.length; i++) {
            if (used[i]) continue;
            if (i > 0 && stones[i] == stones[i - 1] && !used[i - 1]) continue;
            total += stones[i];
            used[i] = true;
            count++;
            solve(stones, used, avg);
            used[i] = false;
            count--;
            total -= stones[i];
        }
    }
}